package com.xbongbong.pro.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * @description: 公告类型
 * @Author: hongxiao
 * @date: 2019-03-25 17:00
 * @since v1.0
 */
@Getter
public enum ActivityTypeEnum {
    /**
     * 公告类型枚举
     */
    DEFAULT(1, "enum.activityType.name.default","default"),


    VERSION_UPGRADE(2, "enum.activityType.name.version_upgrade","update"),


    CARD_COUPON(3, "enum.activityType.name.card_coupon",""),


    ZHI_MA_XIN_YONG(4, "enum.activityType.name.zhi_ma_xin_yong",""),


    STOP_SERVICE(5, "enum.activityType.name.stop_service","stop"),


    VERSION_UPDATING(6, "enum.activityType.name.version_updating","updating");
    /** 枚举值 -- */
    private final int code;
    /** 枚举信息--中文名称 */
    private final String  name;
    private final String alias;

    ActivityTypeEnum(int code, String name, String alias) {
        this.code = code;
        this.name = name;
        this.alias = alias;
    }

    public static ActivityTypeEnum getByCode(Integer code) {
        if(code == null) {
            return DEFAULT;
        }
        for (ActivityTypeEnum cacheCode : values()) {
            if (Objects.equals(cacheCode.getCode(), code)) {
                return cacheCode;
            }
        }
        return DEFAULT;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
